<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" th:href="@{/css/oksub.css}">
</head>
<body>
<div class="layui-container" style="margin-top: 20px">
    <form class="layui-form layui-form-pane" lay-filter="roleForm">

        <div class="layui-form-item">
            <label class="layui-form-label">角色编号</label>
            <div class="layui-input-block">
                <input type="text" name="id" lay-verify="required"
                       placeholder="请输入角色编号" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">角色名称</label>
            <div class="layui-input-block">
                <input type="text" name="roleName" lay-verify="required"
                       placeholder="请输入角色名称" autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">编码</label>
            <div class="layui-input-block">
                <input type="text" name="code" lay-verify="required"
                       placeholder="请输入编码" autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="roleForm">提交</button>

            </div>
        </div>

        <div style="height: 200px"></div>
    </form>
</div>

<script type="text/javascript" th:src="@{/lib/layui/layui.js}"></script>

<script type="text/javascript">
    layui.use([ 'form', 'layer', 'element', 'laydate', 'jquery' ],
        function() {
            $ = layui.jquery;
            form = layui.form;
            layer = layui.layer;
            element = layui.element;


            //监听表单提交事件
            form.on('submit(roleForm)', function(data) {
                var index = top.layer.msg('数据提交中，请稍候', {
                    icon : 16,
                    time : false,
                    shade : 0.8
                });
                var params = data.field;

                $.post("/api/system/addRole" , params, function(d) {
                    if (d.code == 200) {
                        top.layer.close(index);
                        top.layer.msg("操作成功！");
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                    } else {
                        top.layer.close(index);
                        layer.msg(d.msg, {
                            "icon" : 2
                        });
                    }
                });

                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });

        });
</script>
</body>


</html>